#include "modelFriend.h"

ModelFriend::ModelFriend(QObject *parent)
    :QAbstractItemModel(parent){

}

int ModelFriend::columnCount(const QModelIndex &parent) const{
    return 1;
}

int ModelFriend::rowCount(const QModelIndex &parent) const{
    Node *parentNode = nodeFromIndex(parent);
    if(NULL == parentNode){
        return;
    }
    return parentNode->m_children.count();
}
QVariant ModelFriend::data(const QModelIndex &index, int role) const{
    Node *node = nodeFromIndex(index);
    if(NULL == node){
        return QVariant();
    }
    if(Node.FriendGroup == node->getType()){
        GroupNode *gNode = static_cast<GroupNode *>(node);
        switch(role){
            case Node.NAME:
                return gNode->getName();
            case Node.PIX_EXPEND:
                return gNode->getExpendIco();
            case Node.ONLINE_COUNT:
                return gNode->getOnlineCountText();
            default:
                break;
        }
    }else if(Node.Friend == node->getType()){
        FriendNode *fNode = static_cast<FriendNode *>(node);
        switch(role){
            case Node.NAME:
                return fNode->getName();
            case Node.AVATAR:
                return fNode->getAvatar();
            case Node.SIGNATURE:
                return fNode->getPerSignature();
        }
    }
}
